﻿﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <!-- Data Tables -->
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote-bs3.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
    <style type="text/css">
        .ibox-content {
            float: none;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
@stop
@section('content')




    <div class="row" style="display:none" id="div_one">
        <div class="col-lg-6">
            <div class="ibox float-e-margins">
                <div class="ibox-content col-sm-8">
                    <form class="form-horizontal m-t" id="settingForm" action="/admin/setting" method="post" enctype='multipart/form-data'>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">网站标题：</label>
                            <div class="col-sm-6">
                                <input type="text" name="title" class="form-control" placeholder="请输入网站标题">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">网站关键字：</label>
                            <div class="col-sm-6">
                                <input type="text" name="keywords" class="form-control"  placeholder="请输入网站关键字">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">网站描述：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="description" class="form-control" placeholder="请输入网站描述">
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-3 control-label">网站状态：</label>
                            <div class="col-sm-4">
                                <label class="radio-inline">
                                    <input type="radio"  value="1"  name="status">开</label>
                                <label class="radio-inline">
                                    <input type="radio" value="2" name="status">关</label>
                            </div>
                        </div>
                        <div class="list list-title col-sm-12">
                            <label class="col-sm-3 control-label">logo：</label>
                            <img id="pic" src="{{ asset('upload/default.png') }}" width="200" style="background-color:#666">
                            <input style="display: none" type="file" id="img" name="file" >
                            <button type="button" onclick="demo();"  >点击添加<br></button>
                        </div>




                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
                        >提交
                        </button>
                        <div class="clearFix"></div>
                    </form>
                </div>
            </div>

        </div>
    </div>


@stop
@section('script')
    <!-- SUMMERNOTE -->
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote-zh-CN.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>
    <script src="{{ asset('tools/form-builder/beautifyhtml.js') }}"></script>
    <!-- Jquery Validate -->
    <script src="{{ asset('myadmin/js/plugins/validate/jquery.validate.min.js') }}"></script>

    <script src="{{ asset('myadmin/js/plugins/validate/messages_zh.min.js') }}"></script>
    <script>

        @if(!empty(session('success')))
            alert('{{ session('success') }}');
        @endif

    </script>
    <script>

        $.ajax({
            url:'/admin/setting/1/edit',
            async:false,				//是否异步
            type:'get',				//请求方式
            data:{upid:0,_token: "{{ csrf_token() }}"},				//发送的数据
            dataType:'json',			//响应的数据类型
            error:function()			//失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)		//成功时回调函数
            {
                //alert(data);
                if(data!=0){
                    $("input[name='title']").val(data.title);
                    $("input[name='keywords']").val(data.keywords);
                    $("input[name='description']").val(data.description);
                    $("#pic").attr('src',"{{ asset('upload') }}"+'/'+data.logo);
                    if(data.status==1){
                        $("input[name='status'][value='1']").attr('checked',true);
                    }else{
                        $("input[name='status'][value='2']").attr('checked',true);
                    }
                    $("#settingForm").attr('action','/admin/setting/'+data.id);
                    $("#settingForm").append("<input type='hidden' name='_method' value='PUT'>");
                    $('button[type="submit"]').html('更改');
                }else{
                    $("input[name='status'][value='1']").attr('checked',true);
                }

            }
        });


        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
    </script>
    <script>
        $(document).ready(function () {

            $("#settingForm").validate({
                rules: {
                    title: {
                        required: true,
                    },
                    keywords: {
                        required: true,

                    },
                    description: {
                        required: true,

                    },
                    photo: {
                        required: true,
                    }
                }
            });
            $('#div_one').css('display','block')
        });

    </script>



@stop
